package com.boot.study.jianfan;

import cn.hutool.core.lang.ObjectId;
import org.dromara.pdf.fop.doc.XEasyPdfTemplateDocument;
import org.dromara.pdf.fop.doc.component.table.XEasyPdfTemplateTable;
import org.dromara.pdf.fop.doc.page.XEasyPdfTemplatePage;
import org.dromara.pdf.fop.handler.XEasyPdfTemplateHandler;

/**
 * @author lkz
 * @className PdfImage
 * @description
 * @date 2024/3/14 17:21
 **/
public class PdfImage {


    public static void main(String[] args) {
        String outPath = "D:\\pdf\\jianfan\\" + ObjectId.next() + ".pdf";
        XEasyPdfTemplateDocument document = XEasyPdfTemplateHandler.Document.build();
        XEasyPdfTemplatePage page = XEasyPdfTemplateHandler.Page.build();
        page.setId("1")
                .setMarginTop("70pt").setMarginLeft("20pt")
                .setMarginRight("20pt")
                .setFontFamily("宋体");

       page.addBodyComponent(XEasyPdfTemplateHandler.Text.build().setText("图片测试").setHorizontalStyle("center"));
        XEasyPdfTemplateTable table = XEasyPdfTemplateHandler.Table.build();

        table.setBody(XEasyPdfTemplateHandler.Table.Body.build().addRow(
                XEasyPdfTemplateHandler.Table.Row.build().setBorder("solid").addCell(
                        XEasyPdfTemplateHandler.Table.Cell.build().addComponent(XEasyPdfTemplateHandler.Text.build().setText("测试")),
                        XEasyPdfTemplateHandler.Table.Cell.build().addComponent(XEasyPdfTemplateHandler.Image.build()
                                .setWidth("100pt").setHeight("50pt").setPath("https://medical.cdn.jianfancloud.com/edc/subject/visit/20231102_15_48_015门诊病历20231011.jpg")),
                        XEasyPdfTemplateHandler.Table.Cell.build().addComponent(XEasyPdfTemplateHandler.Text.build().setText("图片连接") // 设置超链接 前面要有文本
                                .setLinkExternalDestination("https://medical.cdn.jianfancloud.com/edc/subject/visit/20231102_15_48_015门诊病历20231011.jpg").enableLink())
                )
        ));


        page.addBodyComponent(table);
        document.addPage(page);

        document.transform(outPath);
    }
}
